import { nextTick, onMounted, onUnmounted, reactive, ref } from 'vue';
import { ws } from './utils.js'
export default function useWs(methods) {
  let si = null
  si = setInterval(() => {
    if (ws) {
      clearInterval(si)
      si = null
      if (methods.systemPushMessage) {
        ws && ws.on("SYSTEM_PUSH_MESSAGE", methods.systemPushMessage)
      }
    }
  }, 1000);
  // onMounted(() => {
  //   nextTick(()=> {
  //     if (methods.systemPushMessage) {
  //       ws && ws.on("SYSTEM_PUSH_MESSAGE", methods.systemPushMessage)
  //     }
  //   })
  // })
  onUnmounted(() => {
    if (methods.systemPushMessage) {
      ws && ws.off("SYSTEM_PUSH_MESSAGE", methods.systemPushMessage)
    }
  })
}